﻿using System;
using System.Collections.Generic;
using Sustainalytics.DataLayer;
using Sustainalytics.Entities;
using Sustainalytics.Utils;

namespace Sustainalytics.Accounts.BusinessLogic
{
    public class AccountsManagement : IAccountsManagement
    {
        private IAccountsRepository _accountsRepository;

        private AccountsManagement()
        {

        }

        public AccountsManagement(IAccountsRepository accountsRepository)
        {
            _accountsRepository = accountsRepository;
        }


        public static IAccountsManagement GetInstance(IAccountsRepository accountsRepository)
        {
            return new AccountsManagement {_accountsRepository = accountsRepository};
        }

        public List<Account> GetAccounts(Status? status, string searchText, ListOptions listOptions, bool tier1_or_tier2 = false)
        {
            return _accountsRepository.GetAccounts(status, searchText, listOptions, tier1_or_tier2);
        }

        public int GetAccountsTotalCount(Status? status, string searchText, bool tier1_or_tier2 = false)
        {
            return _accountsRepository.GetAccountsTotalCount(status, searchText, tier1_or_tier2);
        }

        public Account GetAccountById(Guid id)
        {
            return _accountsRepository.GetAccountById(id);
        }

        public List<User> GetUsers(List<Guid> accountsIds, Status? userStatus, string filterText, ListOptions listOptions)
        {
            return _accountsRepository.GetUsers(accountsIds, userStatus, filterText, listOptions);
        }

        public List<Account> GetAccountsByUserSatusAndSearchFilter(Status? userStatus, string filterText)
        {
            return _accountsRepository.GetAccountsByUserSatusAndSearchFilter(userStatus, filterText);
        }

        public int GetUsersTotalCount(List<Guid> accountsIds, Status? userStatus, string filterText)
        {
            return _accountsRepository.GetUsersTotalCount(accountsIds, userStatus, filterText);
        }

        public User GetUserByUserId(Guid userId)
        {
            return _accountsRepository.GetUserByUserId(userId);
        }

        public ClientUser GetClientUserByUserId(Guid userId)
        {
            return _accountsRepository.GetClientUserByUserId(userId);
        }


        public DateTime? GetLastSyncDate(SyncType type)
        {
            return _accountsRepository.GetLastSyncDate(type);
        }
    }
}
